<template>
    <div class="boomContainer">
        <div class="clip-tools_pan">
            爆炸模式
        </div>
        <div id="boomBody">
            <label>距离</label>
            <div class='boomRangeInput'>
                <input type='range' id='boomRange' value="1" min="1" max="10">
            </div>
        </div>
    </div>
</template>

<script>
    // require('@/libs/xeogl/extends/helpers/clipHelper')
    export default {
        name: "boom",
        data:function () {
            return {

            }
        },
        props:[
            'currentTool',
        ],
        methods:{
            boom: function() {
                let boomRange = document.getElementById('boomRange');
                boomRange.addEventListener('input', function(e) {
                    if(e.target.type === 'range') {
                        let oldValue = e.target.getAttribute('old-val');
                        if(!oldValue) {
                            oldValue = 1;
                        }
                        let nowValue = e.target.value;


                        let diffValue = nowValue - oldValue;

                        if(oldValue === 1) {
                            diffValue += 1;
                        }

                        let meshArr = Object.values(GOLOAlBAL_OPEOBJ.storeyDatas);
                        for(let i = 0; i < meshArr.length; i++) {
                            let tempMeshArr = meshArr[i];

                            for(let j = 0; j < tempMeshArr.length; j++) {
                                let oldPosition = GOLOAlBAL_OPEOBJ.bimModel.objects[tempMeshArr[j].guid].position;
                                if(oldValue !== 1) {
                                    GOLOAlBAL_OPEOBJ.bimModel.objects[tempMeshArr[j].guid].position = [
                                        (oldPosition[0] / oldValue) * nowValue,
                                        (oldPosition[1] / oldValue) * nowValue,
                                        (oldPosition[2] / oldValue) * nowValue
                                    ];
                                } else {
                                    GOLOAlBAL_OPEOBJ.bimModel.objects[tempMeshArr[j].guid].position = [
                                        oldPosition[0] * diffValue,
                                        oldPosition[1] * diffValue,
                                        oldPosition[2] * diffValue
                                    ];
                                }
                                // GOLOAlBAL_OPEOBJ.bimModel.objects[tempMeshArr[j].guid].translateZ(diffValue);
                                // GOLOAlBAL_OPEOBJ.bimModel.objects[tempMeshArr[j].guid].translateX(diffValue);
                                // GOLOAlBAL_OPEOBJ.bimModel.objects[tempMeshArr[j].guid].translateY(diffValue);
                            }
                        }

                        oldValue = nowValue;
                        e.target.setAttribute('old-val', oldValue);
                    }
                })
            },
        },
        watch:{
            currentTool:{
                handler(newValue, oldValue) {
                    console.log("ddd")
                    console.log(newValue);
                    console.log(oldValue);
                },
                deep: true
            }
        },
        beforeCreate(){

        },
        created(){

        },
        beforeMount(){

        },
        mounted(){
            this.boom();
        },
        beforeUpdate(){

        },
        updated(){

        },
        beforeDestroy(){

        },
        destroyed(){

        }
    }
</script>

<style scoped>
    @import "./css/boom.css";
</style>
